import { http } from "@/utils/http";
import { baseAdminURLApi } from "./utils";
type OptionsResult = {
  data?: Array<options>;
};
type UserInfoResult = {
  data?: UserInfo;
};
type options = {
  title: any;
  id: number;
  value: string;
};
type UserInfo = {
  id?: number;
  nickname: string;
  username: string;
  avatar: string;
  mobile: string | number;
  email: string;
  gender: string | number;
  roleName: string;
  content: string;
  createTime: Date;
};

type ResultTable = {
  data?: {
    /** 列表数据 */
    list: Array<any>;
    /** 总条目数 */
    total?: number;
    /** 每页显示条目个数 */
    pageSize?: number;
    /** 当前页数 */
    currentPage?: number;
  };
};

type ResultBoolean = {
  data?: boolean;
  code?: number;
  msg?: string;
};

/** 系统管理-用户管理-获取用户管理列表 */
export const getPageList = (data?: object) => {
  return http.request<ResultTable>("get", baseAdminURLApi("/user/page"), {
    params: data
  });
};

/** 系统管理-用户管理-新增用户 */
export const addUser = (data?: object) => {
  return http.request<ResultBoolean>("post", baseAdminURLApi("/user/save"), {
    data
  });
};

/** 系统管理-用户管理-修改用户信息 */
export const updateUser = (data?: object) => {
  return http.request<ResultBoolean>("put", baseAdminURLApi("/user/update"), {
    data
  });
};

/** 系统管理-用户管理-根据id/ids删除用户 */
export const delUserById = (data?: object) => {
  return http.request<ResultBoolean>(
    "delete",
    baseAdminURLApi("/user/delById"),
    {
      params: data
    }
  );
};

/** 系统管理-用户管理-重置用户密码 */
export const resetPassword = (data?: object) => {
  return http.request<ResultBoolean>(
    "patch",
    baseAdminURLApi("/user/resetPassword"),
    {
      data
    }
  );
};

/** 系统管理-用户管理-获取角色下拉列表 */
export const getAllRoleList = () => {
  return http.request<OptionsResult>(
    "get",
    baseAdminURLApi("/role/getAllRoleList")
  );
};

/** 根据用户id和角色id修改用户的角色信息 */
export const updateUserRole = (data?: object) => {
  return http.request<OptionsResult>(
    "put",
    baseAdminURLApi("/user/updateRole"),
    {
      data
    }
  );
};

/** 上传头像 */
export const uploadAvatar = (data?: object) => {
  return http.request<ResultBoolean>(
    "post",
    baseAdminURLApi("/user/uploadAvatar"),
    { data },
    {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    }
  );
};

/** 获取当前用户信息 */
export const getCurrentUser = () => {
  return http.request<UserInfoResult>(
    "get",
    baseAdminURLApi("/user/getCurrentUser")
  );
};

/** 获取系统管理-角色分页列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultTable>("get", baseAdminURLApi("/role/page"), {
    params: data
  });
};

/** 系统管理-角色管理-新增角色 */
export const addRole = (data?: object) => {
  return http.request<ResultBoolean>("post", baseAdminURLApi("/role/save"), {
    data
  });
};

/** 系统管理-角色管理-修改角色信息 */
export const updateRole = (data?: object) => {
  return http.request<ResultBoolean>("put", baseAdminURLApi("/role/update"), {
    data
  });
};

/** 系统管理-角色管理-删除角色信息 */
export const delRoleById = (data?: object) => {
  return http.request<ResultBoolean>(
    "delete",
    baseAdminURLApi("/role/delete"),
    {
      params: data
    }
  );
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单及权限 */
export const getRoleMenuIds = (data?: object) => {
  return http.request<OptionsResult>(
    "get",
    baseAdminURLApi("/role/getRoleMenu"),
    {
      params: data
    }
  );
};

/** 根据角色id修改菜单权限 */
export const updateRoleMenu = (id?: object, data?: object) => {
  return http.request<ResultBoolean>(
    "put",
    baseAdminURLApi("/role/updateRoleMenu"),
    {
      params: id
    },
    { data }
  );
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = () => {
  return http.request<OptionsResult>("post", baseAdminURLApi("/menu/list"));
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<OptionsResult>("get", baseAdminURLApi("/menu/list"), {
    data
  });
};

/** 新增菜单 */
export const addMenu = (data?: object) => {
  return http.request<ResultBoolean>("post", baseAdminURLApi("/menu/save"), {
    data
  });
};

/** 修改菜单 */
export const updateMenu = (data?: object) => {
  return http.request<ResultBoolean>("put", baseAdminURLApi("/menu/update"), {
    data
  });
};

/** 删除菜单 */
export const delMenuById = (data?: object) => {
  return http.request<ResultBoolean>(
    "delete",
    baseAdminURLApi("/menu/delete"),
    {
      params: data
    }
  );
};
